var express = require('express');
var path = require('path');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var sseRouter = require('./routes/sse');
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

//express配置
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));

//所有请求拦截
app.all('/*', function (req, res, next) {
  // console.log(`request start==========>>>${getCurrentTime()} url=>${req.url} \n ip=>${req.ip} \n headers=>${JSON.stringify(req.headers)}\n params=>${JSON.stringify(req.params)} \n body=${JSON.stringify(req.body)}<<<==========`)
  next()
});

//注册接口路由
app.use('/', indexRouter);
app.use('/sse', sseRouter);
//静态文件托管
app.use(express.static('static'));

module.exports = app;
